
/*-----------------------------------------------*
Name: MASTER Do file for Haqdarshak Paper
Date Created: 30 July, 2018
Date Last Modified: 28 April, 2021
Created by: Aaron Berman and modified by Daniela Paz and Saumya Mathur on Nov.13/2020 
Description: This master do file is composed by 12 sub-do files that clean the raw data and produce the tables of the report
*-------------------------------------------------*/



*..................................................
**Install user-written commands
foreach package in mdesc nmissing veracrypt {
     capture which `package'
	 if _rc==111 ssc install `package'
}
*..................................................
clear all
set more off
version 15.0
cap log close
pause off



*--------------------------------------------------
** Set directories (requires adjustment to user's system)
*--------------------------------------------------
//user needs to set path on their computer
//set mounting drive to one that is available on system 
global vcdrive "" //Set the location of the package here



*--- Setting globals ---*
global pilot "$vcdrive/1_Raw_data/Pilot"
global main_experiment "$vcdrive/1_Raw_data/MainExperiment"

global intermediate_data "$vcdrive/2_Intermediate_data" 
global latex "$vcdrive/4_Output/Other_analysis" 
global Main "$vcdrive/4_Output/Main" 
global Appe "$vcdrive/4_Output/Appendix" 

global logs "$vcdrive/5_Log" 

*Locations for do files
global cleaning "$vcdrive/3_Do/cleaning"
global analysis "$vcdrive/3_Do/analysis"


*****************************************
***************///CLEANING***************
*****************************************

//Create data on screening takeup
//Uses 5 raw files: hh_data_treatment_b.dta, individual_data_treatment_b.dta, pilot_intervention_tracking_sheets_all.dta, pilot_baseline_household_roster_all.dta, and  pilot_intervention_household_screening_counts.dta
//Creates 2 intermediate files: household_member_counts and screening_takeup.dta 
do "$cleaning/clean_pilot_for_tables_1_2_screening_takeup" 


//Create data on scheme applications
//Uses 5 raw files: pilot_intervention_completed_apps.dta, hh_data_treatment_b.dta, individual_data_treatment_b.dta, and pilot_intervention_tracking_sheets_all.dta
//Creates 2 intermediate files: scheme_applications_hhlevel.dta and individual_scheme_counts.dta
do "$cleaning/clean_pilot_for_tables_3_4_scheme_applications"


//Create data on scheme amounts
//Uses 6 raw files and 1 intermediate file: pilot_intervention_completed_apps.dta, hh_data_treatment_b.dta, individual_data_treatment_b.dta,pilot_intervention_citizen_cumulative_all, pilot_intervention_completed_apps, pilot_intervention_tracking_sheets_all.dta, and , household_members_count (intermediate file)
//Creates 1 intermediate file: scheme_amounts.dta 
do "$cleaning/clean_pilot_for_tables_5_6_scheme_amounts"

//Clean Endline Take-up 
//Uses from raw: hh_data_treatment_b, pilot_intervention_citizen_cumulative_all, cumulative_family
//Uses from intermediate: endline_takeup and household_counts (check this one)
//Creates 1 intermediate file: endline_takeup_clean.dta 
		
do "$cleaning/clean_endline_takeup"



*****************************************
***************///ANALYSIS***************
*****************************************

//Create Table 1 and Table 2
//Uses: screening_takeup.dta
//Creates: 7 latex tables (including Tables 1 and 2 of our main report)
do "$analysis/analysis_tables_1_2"


//Create Table 3 and Table 4
//Uses: scheme_applications_hhlevel.dta and individual_scheme_counts.dta
//Creates: 4 latex tables (including Tables 3 and 4 of our main report)
do "$analysis/analysis_tables_3_4"


//Create Table 5 and Table 6
//Uses: screen_amounts and pilot_intervention_assitance_followup
//Creates: 2 latex tables (Tables 5 and 6 of our main report)
do "$analysis/analysis_tables_5_6"


//Create Appendix Table 1
//Uses: hh_data_treatment_b and pilot_intervention_household_screening_counts
//Creates: 1 latex table on attrition check for the appendix
do "$analysis/analysis_appendix_1_attrition"


//Create Appendix Tables 2 and 3
//Uses:pilot_intervention_citizen_cumulative_all, pilot_intervention_citizen_cumulative_family, pilot_intervention_tracking_sheets_all and pilot_intervention_completed_apps
//Creates: 2 latex tables on warnings for the appendix 
do "$analysis/analysis_appendix_tables_2_3"


//Create Other Tables-Documents
//Uses: individual_data_documents and hh_data_treatment_b
//Creates: Creates Figure 1 a and b (document take up at baseline) and other tabs for appendix. 
do "$analysis/analysis_tables_appendix_documents"


//Create CrossPriceElasticity Tables
//Uses: pilot_intervention_citizen_cumulative_all, pilot_intervention_tracking_sheets_all, and pilot_intervention_completed_apps
//Creates: 12 latex tables that are not on the main report
do "$analysis/analysis_tables_appendix_cross_price_elasticities"


//Create Endline Regressions 
//Uses: endline_takeup_clean and household_counts 
//Creates: 36 latex tables: for endline regressions (one for each scheme) and for attitudes (4 tables only)
do "$analysis/analysis_tables_endline"





